<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="custom-style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
	<div style="overflow: hidden;">
		<div style="height: 57px;min-width: 1039px;background-size: auto 100%;background:url('');">
			<img src="titleleft.png" style="float: left;"/>
			<img src="titleright.png" alt="" style="float: right;" />
		</div>
	</div>
<!-- 制作者 Doxygen 1.8.15 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>法律声明</span></a></li>
      <li><a href="_xE9_xA6_x96_xE9_xA1_xB5.html"><span>首页</span></a></li>
      <li><a href="_xE6_x9B_xB4_xE6_x96_xB0_xE8_xAE_xB0_xE5_xBD_x95.html"><span>更新记录</span></a></li>
      <li><a href="_xE7_x8E_xAF_xE5_xA2_x83_xE9_x85_x8D_xE7_xBD_xAE.html"><span>环境配置</span></a></li>
      <li><a href="_xE7_xBC_x96_xE7_xA8_x8B_xE5_xBC_x95_xE5_xAF_xBC.html"><span>编程引导</span></a></li>
      <li><a href="modules.html"><span>接口说明</span></a></li>
      <li><a href="annotated.html"><span>结构体定义</span></a></li>
      <li><a href="_xE7_x9B_xB8_xE6_x9C_xBA_xE5_x8F_x82_xE6_x95_xB0_xE8_x8A_x82_xE7_x82_xB9_xE8_xA1_xA8.html"><span>相机参数节点表</span></a></li>
      <li><a href="examples.html"><span>示例程序</span></a></li>
      <li><a href="_xE9_x94_x99_xE8_xAF_xAF_xE7_xA0_x81.html"><span>状态码</span></a></li>
      <li><a href="_xE5_xB8_xB8_xE8_xA7_x81_xE9_x97_xAE_xE9_xA2_x98.html"><span>常见问题</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Grab_Asynchronous.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>异步取图及处理</p>
<p>该示例程序说明如何异步取图并进行图像处理，规避了同步时可能存在的耗时长问题。</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;pthread.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;mutex&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;thread&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;MvCameraControl.h&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span>std;</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> g_bExit = <span class="keyword">false</span>;  <span class="comment">//线程结束标记</span></div><div class="line"><span class="preprocessor">#define Max_Count 5       //队列 缓冲区个数； 根据实际情况调节</span></div><div class="line"><span class="keywordtype">int</span> m_nImageSize = 0;    <span class="comment">// 图像大小</span></div><div class="line"><span class="comment">//自定义保存的图像信息的结构体</span></div><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>_stImageNode_</div><div class="line">{</div><div class="line"></div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pData;</div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nFrameLen;</div><div class="line">    </div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> nWidth;</div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> nHeight;</div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nFrameNum;</div><div class="line">}stImageNode;</div><div class="line"></div><div class="line"><span class="keyword">class </span>ArrayQueue</div><div class="line">{</div><div class="line"><span class="keyword">public</span>:</div><div class="line">    ArrayQueue()</div><div class="line">    {</div><div class="line">        this-&gt;size = 0;</div><div class="line">        this-&gt;start = 0;</div><div class="line">        this-&gt;end = 0;</div><div class="line">        this-&gt;Queue = NULL;</div><div class="line">        this-&gt;Qlen = 0;</div><div class="line">    }</div><div class="line">    </div><div class="line"></div><div class="line">    ~ArrayQueue()</div><div class="line">    {</div><div class="line">        g_mutex.lock();</div><div class="line">        </div><div class="line"></div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i&lt; Qlen; i++)</div><div class="line">        {</div><div class="line">            Queue[i].nFrameNum = 0;</div><div class="line">            Queue[i].nHeight = 0;</div><div class="line">            Queue[i].nWidth = 0;</div><div class="line">            Queue[i].nFrameLen = 0;  </div><div class="line">            <span class="keywordflow">if</span>(Queue[i].pData != NULL)</div><div class="line">            {</div><div class="line">                free(Queue[i].pData);</div><div class="line">                Queue[i].pData = NULL;</div><div class="line">            }                    </div><div class="line"></div><div class="line">            printf(<span class="stringliteral">&quot; free ArrayQueue [%d] !\r\n&quot;</span>,i);</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keyword">delete</span> []Queue;</div><div class="line">        Queue = NULL;</div><div class="line"></div><div class="line">        size = 0;</div><div class="line">        start = 0;</div><div class="line">        end = 0;</div><div class="line"></div><div class="line">        g_mutex.unlock();</div><div class="line"></div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// 队列初始化</span></div><div class="line">    <span class="keywordtype">int</span> Init(<span class="keywordtype">int</span> nBufCount, <span class="keywordtype">int</span> DefaultImagelen)</div><div class="line">    {</div><div class="line">        <span class="keywordtype">int</span> nRet = 0 ;</div><div class="line"></div><div class="line">        this-&gt;Queue = <span class="keyword">new</span> (std::nothrow)stImageNode[nBufCount];</div><div class="line">        <span class="keywordflow">if</span> (this-&gt;Queue == NULL)</div><div class="line">        {</div><div class="line">            <span class="keywordflow">return</span> MV_E_RESOURCE;</div><div class="line">        }</div><div class="line">        this-&gt;Qlen = nBufCount;</div><div class="line"></div><div class="line"></div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i&lt; nBufCount; i++)</div><div class="line">        {</div><div class="line">            Queue[i].nFrameNum = 0;</div><div class="line">            Queue[i].nHeight = 0;</div><div class="line">            Queue[i].nWidth = 0;</div><div class="line">            Queue[i].nFrameLen = 0;          </div><div class="line">            Queue[i].pData = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)malloc(DefaultImagelen);</div><div class="line">            <span class="keywordflow">if</span>(NULL ==  Queue[i].pData)</div><div class="line">            {</div><div class="line">                <span class="keywordflow">return</span> MV_E_RESOURCE;</div><div class="line">            }</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line"></div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// 数据放入队列</span></div><div class="line">    <span class="keywordtype">int</span> push(<span class="keywordtype">int</span> nFrameNum, <span class="keywordtype">int</span> nHeight, <span class="keywordtype">int</span> nWidth, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pData, <span class="keywordtype">int</span> nFrameLen)</div><div class="line">    {</div><div class="line">        g_mutex.lock();</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (size==Qlen)</div><div class="line">        {</div><div class="line">            g_mutex.unlock();</div><div class="line">            <span class="keywordflow">return</span> MV_E_BUFOVER;</div><div class="line">        }</div><div class="line"></div><div class="line"></div><div class="line">        size++;</div><div class="line">        Queue[end].nFrameNum = nFrameNum;</div><div class="line">        Queue[end].nHeight = nHeight;</div><div class="line">        Queue[end].nWidth = nWidth;</div><div class="line">        Queue[end].nFrameLen = nFrameLen;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (NULL !=  Queue[end].pData  &amp;&amp; NULL != pData)</div><div class="line">        {</div><div class="line">            memcpy(Queue[end].pData, pData, nFrameLen);</div><div class="line">        }</div><div class="line"></div><div class="line">        end = end == Qlen - 1 ? 0 : end + 1;</div><div class="line">        g_mutex.unlock();</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// 数据从队列中取出</span></div><div class="line">    <span class="keywordtype">int</span>  poll(<span class="keywordtype">int</span> &amp;nFrameNum, <span class="keywordtype">int</span> &amp;nHeight, <span class="keywordtype">int</span> &amp;nWidth, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pData, <span class="keywordtype">int</span> &amp;nFrameLen)</div><div class="line">    {</div><div class="line"></div><div class="line">        g_mutex.lock();</div><div class="line">        </div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (size == 0)</div><div class="line">        {</div><div class="line">            g_mutex.unlock();</div><div class="line">            <span class="keywordflow">return</span>  MV_E_NODATA;</div><div class="line">        }</div><div class="line"></div><div class="line"></div><div class="line">        nFrameNum =Queue[start].nFrameNum;</div><div class="line">        nHeight =Queue[start].nHeight;</div><div class="line">        nWidth =Queue[start].nWidth;</div><div class="line">        nFrameLen =Queue[start].nFrameLen;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (NULL !=  pData &amp;&amp; NULL != Queue[start].pData)</div><div class="line">        {</div><div class="line">            memcpy( pData,Queue[start].pData, nFrameLen);</div><div class="line">        }</div><div class="line"></div><div class="line">        size--;</div><div class="line">        start = start == Qlen - 1 ? 0 : start + 1;</div><div class="line"></div><div class="line">        g_mutex.unlock();</div><div class="line"></div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">    }</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">private</span>:</div><div class="line">    stImageNode *Queue;</div><div class="line">    <span class="keywordtype">int</span> size;</div><div class="line">    <span class="keywordtype">int</span> start;</div><div class="line">    <span class="keywordtype">int</span> end;</div><div class="line">    <span class="keywordtype">int</span> Qlen;</div><div class="line"></div><div class="line">    std::mutex g_mutex; <span class="comment">//互斥锁</span></div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line">ArrayQueue * m_queue = NULL;      <span class="comment">//线程通信队列</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// 等待用户输入enter键来结束取流或结束程序</span></div><div class="line"><span class="comment">// wait for user to input enter to stop grabbing or end the sample program</span></div><div class="line"><span class="keywordtype">void</span> PressEnterToExit(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">    <span class="keywordtype">int</span> c;</div><div class="line">    <span class="keywordflow">while</span> ( (c = getchar()) != <span class="charliteral">&#39;\n&#39;</span> &amp;&amp; c != EOF );</div><div class="line">    fprintf( stderr, <span class="stringliteral">&quot;\nPress enter to exit.\n&quot;</span>);</div><div class="line">    <span class="keywordflow">while</span>( getchar() != <span class="charliteral">&#39;\n&#39;</span>);</div><div class="line">    g_bExit = <span class="keyword">true</span>;</div><div class="line">    sleep(1);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> PrintDeviceInfo(<a name="_a0"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html">MV_CC_DEVICE_INFO</a>* pstMVDevInfo)</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span> (NULL == pstMVDevInfo)</div><div class="line">    {</div><div class="line">        printf(<span class="stringliteral">&quot;The Pointer of pstMVDevInfo is NULL!\n&quot;</span>);</div><div class="line">        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> (pstMVDevInfo-&gt;<a name="a1"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#a3b26b1c9681dba57af81bdb7ed795575">nTLayerType</a> == <a name="a2"></a><a class="code" href="group___xE5_xAE_x8F_xE5_xAE_x9A_xE4_xB9_x89.html#gae1780ad0d41bcd2e835ab81155b398e6">MV_GIGE_DEVICE</a>)</div><div class="line">    {</div><div class="line">        <span class="keywordtype">int</span> nIp1 = ((pstMVDevInfo-&gt;<a name="a3"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a name="a4"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#aab5fcc9de5a7fa798f170a8453818cc5">stGigEInfo</a>.<a name="a5"></a><a class="code" href="struct_m_v___g_i_g_e___d_e_v_i_c_e___i_n_f_o.html#aea1e6f183f4d5cf372af1add35691563">nCurrentIp</a> &amp; 0xff000000) &gt;&gt; 24);</div><div class="line">        <span class="keywordtype">int</span> nIp2 = ((pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#aab5fcc9de5a7fa798f170a8453818cc5">stGigEInfo</a>.<a class="code" href="struct_m_v___g_i_g_e___d_e_v_i_c_e___i_n_f_o.html#aea1e6f183f4d5cf372af1add35691563">nCurrentIp</a> &amp; 0x00ff0000) &gt;&gt; 16);</div><div class="line">        <span class="keywordtype">int</span> nIp3 = ((pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#aab5fcc9de5a7fa798f170a8453818cc5">stGigEInfo</a>.<a class="code" href="struct_m_v___g_i_g_e___d_e_v_i_c_e___i_n_f_o.html#aea1e6f183f4d5cf372af1add35691563">nCurrentIp</a> &amp; 0x0000ff00) &gt;&gt; 8);</div><div class="line">        <span class="keywordtype">int</span> nIp4 = (pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#aab5fcc9de5a7fa798f170a8453818cc5">stGigEInfo</a>.<a class="code" href="struct_m_v___g_i_g_e___d_e_v_i_c_e___i_n_f_o.html#aea1e6f183f4d5cf372af1add35691563">nCurrentIp</a> &amp; 0x000000ff);</div><div class="line"></div><div class="line">        <span class="comment">// ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name</span></div><div class="line">        printf(<span class="stringliteral">&quot;Device Model Name: %s\n&quot;</span>, pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#aab5fcc9de5a7fa798f170a8453818cc5">stGigEInfo</a>.<a name="a6"></a><a class="code" href="struct_m_v___g_i_g_e___d_e_v_i_c_e___i_n_f_o.html#a0444c9bb101455ec9303a2c0cf9052c1">chModelName</a>);</div><div class="line">        printf(<span class="stringliteral">&quot;CurrentIp: %d.%d.%d.%d\n&quot;</span> , nIp1, nIp2, nIp3, nIp4);</div><div class="line">        printf(<span class="stringliteral">&quot;UserDefinedName: %s\n\n&quot;</span> , pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#aab5fcc9de5a7fa798f170a8453818cc5">stGigEInfo</a>.<a name="a7"></a><a class="code" href="struct_m_v___g_i_g_e___d_e_v_i_c_e___i_n_f_o.html#aae7ffce31c7dd8e1c98aab32776e5080">chUserDefinedName</a>);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#a3b26b1c9681dba57af81bdb7ed795575">nTLayerType</a> == <a name="a8"></a><a class="code" href="group___xE5_xAE_x8F_xE5_xAE_x9A_xE4_xB9_x89.html#ga356c3a2b4efad3bea955ecb54e1632fe">MV_USB_DEVICE</a>)</div><div class="line">    {</div><div class="line">        printf(<span class="stringliteral">&quot;Device Model Name: %s\n&quot;</span>, pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a name="a9"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#a3bea622a6d4adb297c2a8c99f28c54eb">stUsb3VInfo</a>.<a name="a10"></a><a class="code" href="struct_m_v___u_s_b3___d_e_v_i_c_e___i_n_f_o.html#a1fd78924df9302fb6421706ddb10c6db">chModelName</a>);</div><div class="line">        printf(<span class="stringliteral">&quot;UserDefinedName: %s\n\n&quot;</span>, pstMVDevInfo-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#ad8047fbdb096b8801b869f00db151c69">SpecialInfo</a>.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#a3bea622a6d4adb297c2a8c99f28c54eb">stUsb3VInfo</a>.<a name="a11"></a><a class="code" href="struct_m_v___u_s_b3___d_e_v_i_c_e___i_n_f_o.html#a5749014e9a3d16bdca2d0cfb9f1f7e16">chUserDefinedName</a>);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">    {</div><div class="line">        printf(<span class="stringliteral">&quot;Not support.\n&quot;</span>);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> __stdcall ImageCallBackEx(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * pData, <a name="_a12"></a><a class="code" href="struct_m_v___f_r_a_m_e___o_u_t___i_n_f_o___e_x.html">MV_FRAME_OUT_INFO_EX</a>* pFrameInfo, <span class="keywordtype">void</span>* pUser)</div><div class="line">{   </div><div class="line">    <span class="keywordflow">if</span> (NULL ==  pFrameInfo ||  NULL ==  pData)</div><div class="line">    {</div><div class="line">        printf(<span class="stringliteral">&quot;ImageCallBackEx Input Param invalid.\n&quot;</span>);</div><div class="line">        <span class="keywordflow">return</span>;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> nRet = MV_OK;</div><div class="line">    nRet = m_queue-&gt;push(pFrameInfo-&gt;<a name="a13"></a><a class="code" href="struct_m_v___f_r_a_m_e___o_u_t___i_n_f_o___e_x.html#a6f8d00948b2d76ac8cd65fda0acc2ed6">nFrameNum</a>, pFrameInfo-&gt;<a name="a14"></a><a class="code" href="struct_m_v___f_r_a_m_e___o_u_t___i_n_f_o___e_x.html#a523c75b72da2a3bb32b97032f86c4703">nWidth</a>, pFrameInfo-&gt;<a name="a15"></a><a class="code" href="struct_m_v___f_r_a_m_e___o_u_t___i_n_f_o___e_x.html#a33071a62b54a3c9a671a0fcbe4804f1a">nHeight</a>,pData, pFrameInfo-&gt;<a name="a16"></a><a class="code" href="struct_m_v___f_r_a_m_e___o_u_t___i_n_f_o___e_x.html#ad6d9155e189b8aab2a81609a8b33c6dc">nFrameLen</a>);<span class="comment">//固定数组实现队列故是10 9 8 7 6 5 4 3 2 1</span></div><div class="line">    <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">    {</div><div class="line">        printf(<span class="stringliteral">&quot;Add Image [%d] to list  failed. \r\n&quot;</span>, pFrameInfo-&gt;<a class="code" href="struct_m_v___f_r_a_m_e___o_u_t___i_n_f_o___e_x.html#a6f8d00948b2d76ac8cd65fda0acc2ed6">nFrameNum</a>);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">    {</div><div class="line">        printf(<span class="stringliteral">&quot;Add Image [%d] to list  success. \r\n&quot;</span>, pFrameInfo-&gt;<a class="code" href="struct_m_v___f_r_a_m_e___o_u_t___i_n_f_o___e_x.html#a6f8d00948b2d76ac8cd65fda0acc2ed6">nFrameNum</a>);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span>* WorkThread(<span class="keywordtype">void</span>* pUser)</div><div class="line">{</div><div class="line">    <span class="keywordtype">int</span> nRet = MV_OK;</div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> nWidth = 0;</div><div class="line">    <span class="keywordtype">int</span> nHeight = 0;</div><div class="line">    <span class="keywordtype">int</span> nFrameLen= 0;</div><div class="line">    <span class="keywordtype">int</span> nFrameNum = 0;</div><div class="line">    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pOutData = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) malloc(m_nImageSize);</div><div class="line">    <span class="keywordflow">if</span> (NULL == pOutData)</div><div class="line">    {</div><div class="line">        printf(<span class="stringliteral">&quot;WorkThread malloc size [%d] failed. \r\n&quot;</span>,m_nImageSize);</div><div class="line">        <span class="keywordflow">return</span>  NULL;</div><div class="line">    }</div><div class="line">    printf(<span class="stringliteral">&quot;WorkThread Begin . \r\n&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line">    <span class="keywordflow">while</span>(<span class="keyword">true</span> != g_bExit)</div><div class="line">    {</div><div class="line"></div><div class="line">        nWidth = 0;</div><div class="line">        nHeight = 0;</div><div class="line">        nFrameLen = 0;</div><div class="line">        nFrameNum = 0;</div><div class="line"></div><div class="line">        nRet = m_queue-&gt;poll(nFrameNum,nHeight,nWidth,pOutData,nFrameLen);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Poll failed, maybe no data. \r\n&quot;</span>);</div><div class="line">            usleep(1*1000*2);<span class="comment">//根据实际情况调节;</span></div><div class="line">            <span class="keywordflow">continue</span>;</div><div class="line">        }</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Get nWidth [%d] nHeight [%d] nFrameNum [%d]  \r\n&quot;</span>,nWidth,nHeight,nFrameNum);</div><div class="line"></div><div class="line">             <span class="comment">//根据实际场景需求，对图像进行 处理   </span></div><div class="line"><span class="preprocessor">#if 0</span></div><div class="line">            FILE* fp = NULL;</div><div class="line">            <span class="keywordtype">char</span> szFileName[256] = {0};</div><div class="line">            sprintf(szFileName, <span class="stringliteral">&quot;Image_%d_width_%d_height_%d_Len_%d.raw&quot;</span>,nFrameNum,nWidth,nHeight,nFrameLen);</div><div class="line">            fp = fopen(szFileName, <span class="stringliteral">&quot;wb+&quot;</span>);</div><div class="line">            <span class="keywordflow">if</span> (fp == NULL)</div><div class="line">            {</div><div class="line">                <span class="keywordflow">return</span> MV_E_RESOURCE;</div><div class="line">            }</div><div class="line">            fwrite(pOutData, 1, nFrameLen, fp);</div><div class="line">            fclose(fp);</div><div class="line">            fp = NULL;</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line">        }</div><div class="line">    }</div><div class="line"></div><div class="line">    printf(<span class="stringliteral">&quot;WorkThread exit . \r\n&quot;</span>);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (pOutData)</div><div class="line">    {</div><div class="line">        free(pOutData);</div><div class="line">        pOutData = NULL;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> NULL;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main()</div><div class="line">{</div><div class="line">    <span class="keywordtype">int</span> nRet = MV_OK;</div><div class="line">    <span class="keywordtype">void</span>* handle = NULL;</div><div class="line">    <span class="keywordflow">do</span> </div><div class="line">    {</div><div class="line">        <span class="comment">// ch:初始化SDK | en:Initialize SDK</span></div><div class="line">        nRet = <a name="a17"></a><a class="code" href="group___s_d_k_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#ga768544eb6e6435313dd99ee9cf92d59d">MV_CC_Initialize</a>();</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Initialize SDK fail! nRet [0x%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <a name="_a18"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html">MV_CC_DEVICE_INFO_LIST</a> stDeviceList;</div><div class="line">        memset(&amp;stDeviceList, 0, <span class="keyword">sizeof</span>(<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html">MV_CC_DEVICE_INFO_LIST</a>));</div><div class="line"></div><div class="line">        <span class="comment">// 枚举设备</span></div><div class="line">        <span class="comment">// enum device</span></div><div class="line">        nRet = <a name="a19"></a><a class="code" href="group___xE7_x9B_xB8_xE6_x9C_xBA_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#ga88741869e2b3c12e47025e53e6a7b58b">MV_CC_EnumDevices</a>(<a class="code" href="group___xE5_xAE_x8F_xE5_xAE_x9A_xE4_xB9_x89.html#gae1780ad0d41bcd2e835ab81155b398e6">MV_GIGE_DEVICE</a> | <a class="code" href="group___xE5_xAE_x8F_xE5_xAE_x9A_xE4_xB9_x89.html#ga356c3a2b4efad3bea955ecb54e1632fe">MV_USB_DEVICE</a>, &amp;stDeviceList);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_EnumDevices fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (stDeviceList.<a name="a20"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html#a757ade91f37b0c95b768035d0ec07fdc">nDeviceNum</a> &gt; 0)</div><div class="line">        {</div><div class="line">            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; stDeviceList.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html#a757ade91f37b0c95b768035d0ec07fdc">nDeviceNum</a>; i++)</div><div class="line">            {</div><div class="line">                printf(<span class="stringliteral">&quot;[device %d]:\n&quot;</span>, i);</div><div class="line">                <a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html">MV_CC_DEVICE_INFO</a>* pDeviceInfo = stDeviceList.<a name="a21"></a><a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html#ac8a3f91cd4d9e7f09ff4abaac031dffc">pDeviceInfo</a>[i];</div><div class="line">                <span class="keywordflow">if</span> (NULL == pDeviceInfo)</div><div class="line">                {</div><div class="line">                    <span class="keywordflow">break</span>;</div><div class="line">                } </div><div class="line">                PrintDeviceInfo(pDeviceInfo);            </div><div class="line">            }  </div><div class="line">        } </div><div class="line">        <span class="keywordflow">else</span></div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Find No Devices!\n&quot;</span>);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        printf(<span class="stringliteral">&quot;Please Intput camera index: &quot;</span>);</div><div class="line">        <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nIndex = 0;</div><div class="line">        scanf(<span class="stringliteral">&quot;%d&quot;</span>, &amp;nIndex);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (nIndex &gt;= stDeviceList.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html#a757ade91f37b0c95b768035d0ec07fdc">nDeviceNum</a>)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Intput error!\n&quot;</span>);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">// 选择设备并创建句柄</span></div><div class="line">        <span class="comment">// select device and create handle</span></div><div class="line">        nRet = <a name="a22"></a><a class="code" href="group___xE7_x9B_xB8_xE6_x9C_xBA_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#gaf10f0644caa6d4dd39fd8c14f8736153">MV_CC_CreateHandle</a>(&amp;handle, stDeviceList.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html#ac8a3f91cd4d9e7f09ff4abaac031dffc">pDeviceInfo</a>[nIndex]);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_CreateHandle fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">// 打开设备</span></div><div class="line">        <span class="comment">// open device</span></div><div class="line">        nRet = <a name="a23"></a><a class="code" href="group___xE7_x9B_xB8_xE6_x9C_xBA_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#ga308c9a9869be7a457d27aadd94ce57dd">MV_CC_OpenDevice</a>(handle);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_OpenDevice fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        </div><div class="line">        <span class="keywordtype">int</span> nWidth = 0;</div><div class="line">        <span class="keywordtype">int</span> nHeight = 0;</div><div class="line"></div><div class="line">        <a name="_a24"></a><a class="code" href="struct_m_v_c_c___i_n_t_v_a_l_u_e___e_x.html">MVCC_INTVALUE_EX</a> stIntEx  = {0}; </div><div class="line">        nRet = <a name="a25"></a><a class="code" href="group___xE5_xB1_x9E_xE6_x80_xA7_xE9_x85_x8D_xE7_xBD_xAE.html#ga6240aac97e206f77b4ce3bd7a1ef1048">MV_CC_GetIntValueEx</a>(handle, <span class="stringliteral">&quot;Width&quot;</span>, &amp;stIntEx);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Get IntValue fail! nRet [0x%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        nWidth = stIntEx.<a name="a26"></a><a class="code" href="struct_m_v_c_c___i_n_t_v_a_l_u_e___e_x.html#a75858d445833ad0bbe60edfa610f7f7b">nCurValue</a>;</div><div class="line"></div><div class="line">        </div><div class="line">        memset(&amp;stIntEx, 0, <span class="keyword">sizeof</span>(<a class="code" href="struct_m_v_c_c___i_n_t_v_a_l_u_e___e_x.html">MVCC_INTVALUE_EX</a>));</div><div class="line">        nRet = <a class="code" href="group___xE5_xB1_x9E_xE6_x80_xA7_xE9_x85_x8D_xE7_xBD_xAE.html#ga6240aac97e206f77b4ce3bd7a1ef1048">MV_CC_GetIntValueEx</a>(handle, <span class="stringliteral">&quot;Height&quot;</span>, &amp;stIntEx);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Get IntValue fail! nRet [0x%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        nHeight = stIntEx.<a class="code" href="struct_m_v_c_c___i_n_t_v_a_l_u_e___e_x.html#a75858d445833ad0bbe60edfa610f7f7b">nCurValue</a>;</div><div class="line">             </div><div class="line">        </div><div class="line">        nRet = <a class="code" href="group___xE5_xB1_x9E_xE6_x80_xA7_xE9_x85_x8D_xE7_xBD_xAE.html#ga6240aac97e206f77b4ce3bd7a1ef1048">MV_CC_GetIntValueEx</a>(handle, <span class="stringliteral">&quot;PayloadSize&quot;</span>, &amp;stIntEx);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;Get IntValue fail! nRet [0x%x], use [%d] replace.\n&quot;</span>, nRet, nHeight*nWidth*3);</div><div class="line">            m_nImageSize =  nHeight*nWidth*3; </div><div class="line">        }</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">        {</div><div class="line">           m_nImageSize =  stIntEx.<a class="code" href="struct_m_v_c_c___i_n_t_v_a_l_u_e___e_x.html#a75858d445833ad0bbe60edfa610f7f7b">nCurValue</a>;</div><div class="line">        }</div><div class="line">        <span class="comment">//初始化队列</span></div><div class="line">        m_queue = <span class="keyword">new</span> (std::nothrow)ArrayQueue();</div><div class="line">        <span class="keywordflow">if</span> (m_queue==NULL)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;m_queue is null! \n&quot;</span>);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        nRet = m_queue-&gt;Init(Max_Count,m_nImageSize);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;ArrayQueue init fail! nRet [0x%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        <span class="comment">// ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)</span></div><div class="line">        <span class="keywordflow">if</span> (stDeviceList.<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o___l_i_s_t.html#ac8a3f91cd4d9e7f09ff4abaac031dffc">pDeviceInfo</a>[nIndex]-&gt;<a class="code" href="struct_m_v___c_c___d_e_v_i_c_e___i_n_f_o.html#a3b26b1c9681dba57af81bdb7ed795575">nTLayerType</a> == <a class="code" href="group___xE5_xAE_x8F_xE5_xAE_x9A_xE4_xB9_x89.html#gae1780ad0d41bcd2e835ab81155b398e6">MV_GIGE_DEVICE</a>)</div><div class="line">        {</div><div class="line">            <span class="keywordtype">int</span> nPacketSize = <a name="a27"></a><a class="code" href="group___gig_e_xE7_x9B_xB8_xE6_x9C_xBA.html#ga9df4e6a7acbd6e6a6952e01949efc18b">MV_CC_GetOptimalPacketSize</a>(handle);</div><div class="line">            <span class="keywordflow">if</span> (nPacketSize &gt; 0)</div><div class="line">            {</div><div class="line">                nRet = <a name="a28"></a><a class="code" href="group___xE5_xBA_x9F_xE5_xBC_x83_xE6_x8E_xA5_xE5_x8F_xA3.html#ga6323cf15f3319cb2b23646c1ca03c166">MV_CC_SetIntValue</a>(handle,<span class="stringliteral">&quot;GevSCPSPacketSize&quot;</span>,nPacketSize);</div><div class="line">                <span class="keywordflow">if</span>(nRet != MV_OK)</div><div class="line">                {</div><div class="line">                    printf(<span class="stringliteral">&quot;Warning: Set Packet Size fail nRet [0x%x]!\n&quot;</span>, nRet);</div><div class="line">                }</div><div class="line">            }</div><div class="line">            <span class="keywordflow">else</span></div><div class="line">            {</div><div class="line">                printf(<span class="stringliteral">&quot;Warning: Get Packet Size fail nRet [0x%x]!\n&quot;</span>, nPacketSize);</div><div class="line">            }</div><div class="line">        }</div><div class="line"></div><div class="line">        </div><div class="line">        nRet = <a name="a29"></a><a class="code" href="group___xE5_xB1_x9E_xE6_x80_xA7_xE9_x85_x8D_xE7_xBD_xAE.html#gad725e29bc56fa0eb57dfefb4d8d6ea69">MV_CC_SetBoolValue</a>(handle, <span class="stringliteral">&quot;AcquisitionFrameRateEnable&quot;</span>, <span class="keyword">false</span>);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;set AcquisitionFrameRateEnable fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        </div><div class="line">        <span class="comment">// 设置触发模式为on</span></div><div class="line">        <span class="comment">// set trigger mode as on</span></div><div class="line">        nRet = <a name="a30"></a><a class="code" href="group___xE5_xB1_x9E_xE6_x80_xA7_xE9_x85_x8D_xE7_xBD_xAE.html#ga15a8abe28a1c5a53e10d115c7def4089">MV_CC_SetEnumValue</a>(handle, <span class="stringliteral">&quot;TriggerMode&quot;</span>, <a name="a31"></a><a class="code" href="group___xE7_xB1_xBB_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gga0c8acd46a8855d93c57b0921b4f9bde9a673e3eb298399f4f80866b97e8f2704c">MV_TRIGGER_MODE_OFF</a>);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_SetTriggerMode fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">// 注册抓图回调</span></div><div class="line">        <span class="comment">// register image callback</span></div><div class="line">        nRet = <a name="a32"></a><a class="code" href="group___xE5_x9B_xBE_xE5_x83_x8F_xE9_x87_x87_xE9_x9B_x86.html#ga48d1c4ef073e39622fa01994a8fe010c">MV_CC_RegisterImageCallBackEx</a>(handle, ImageCallBackEx, handle);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_RegisterImageCallBackEx fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>; </div><div class="line">        }</div><div class="line"></div><div class="line">        pthread_t nThreadID;</div><div class="line">        nRet = pthread_create(&amp;nThreadID, NULL ,WorkThread , handle);</div><div class="line">        <span class="keywordflow">if</span> (nRet != 0)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;thread create failed.ret = %d\n&quot;</span>,nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">// 开始取流</span></div><div class="line">        <span class="comment">// start grab image</span></div><div class="line">        nRet = <a name="a33"></a><a class="code" href="group___xE5_x9B_xBE_xE5_x83_x8F_xE9_x87_x87_xE9_x9B_x86.html#ga78728211c47c6f118110fde635d6ac69">MV_CC_StartGrabbing</a>(handle);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_StartGrabbing fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        PressEnterToExit();</div><div class="line"></div><div class="line">        <span class="comment">// 停止取流</span></div><div class="line">        <span class="comment">// end grab image</span></div><div class="line">        nRet = <a name="a34"></a><a class="code" href="group___xE5_x9B_xBE_xE5_x83_x8F_xE9_x87_x87_xE9_x9B_x86.html#gae5d7f4ae46a53851f104e26fa449ab06">MV_CC_StopGrabbing</a>(handle);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_StopGrabbing fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">// 注销抓图回调</span></div><div class="line">        <span class="comment">// unregister image callback</span></div><div class="line">        nRet = <a class="code" href="group___xE5_x9B_xBE_xE5_x83_x8F_xE9_x87_x87_xE9_x9B_x86.html#ga48d1c4ef073e39622fa01994a8fe010c">MV_CC_RegisterImageCallBackEx</a>(handle, NULL, NULL);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;UnRegisterImageCallBackEx fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>; </div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">// 关闭设备</span></div><div class="line">        <span class="comment">// close device</span></div><div class="line">        nRet = <a name="a35"></a><a class="code" href="group___xE7_x9B_xB8_xE6_x9C_xBA_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#ga33853bd328f46492102246ca8b645d57">MV_CC_CloseDevice</a>(handle);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_CloseDevice fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">// 销毁句柄</span></div><div class="line">        <span class="comment">// destroy handle</span></div><div class="line">        nRet = <a name="a36"></a><a class="code" href="group___xE7_x9B_xB8_xE6_x9C_xBA_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#ga0f74372a22e8a19fa7e21dad45070428">MV_CC_DestroyHandle</a>(handle);</div><div class="line">        <span class="keywordflow">if</span> (MV_OK != nRet)</div><div class="line">        {</div><div class="line">            printf(<span class="stringliteral">&quot;MV_CC_DestroyHandle fail! nRet [%x]\n&quot;</span>, nRet);</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">        handle = NULL;</div><div class="line"></div><div class="line">    } <span class="keywordflow">while</span> (0);</div><div class="line"></div><div class="line">    <span class="comment">//释放资源</span></div><div class="line">    <span class="keywordflow">if</span> (m_queue)</div><div class="line">    {</div><div class="line">        <span class="keyword">delete</span> m_queue;</div><div class="line">        m_queue = NULL;</div><div class="line">    }</div><div class="line">    </div><div class="line">    printf(<span class="stringliteral">&quot;free buffer done\n&quot;</span>);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (handle != NULL)</div><div class="line">    {</div><div class="line">        <a class="code" href="group___xE7_x9B_xB8_xE6_x9C_xBA_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#ga0f74372a22e8a19fa7e21dad45070428">MV_CC_DestroyHandle</a>(handle);</div><div class="line">        handle = NULL;</div><div class="line">    }</div><div class="line">   </div><div class="line">    <span class="comment">// ch:反初始化SDK | en:Finalize SDK</span></div><div class="line">    <a name="a37"></a><a class="code" href="group___s_d_k_xE5_x88_x9D_xE5_xA7_x8B_xE5_x8C_x96.html#gafa1820a0da8671fc6f77dc9a7dfa69d3">MV_CC_Finalize</a>();</div><div class="line"></div><div class="line">    printf(<span class="stringliteral">&quot;exit.\n&quot;</span>);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<div class="footer" style="text-align: right;">
	<hr/>
	<small></small>
</div>
<script>
	// 当前选中的菜单
	var currentMenuItem = document.querySelector('.tablist > li.current > a')
	if (currentMenuItem) { // 子菜单情况
	  window.parent.postMessage({
		navHref: currentMenuItem.href
	  }, '*')
	} else {
	  window.parent.postMessage({
		url: window.location.href
	  }, '*')
	}
  </script>
</body>
</html>